package com.deer.wms.base.system.web;

import com.deer.wms.base.system.model.map.CarCoord;
import com.deer.wms.base.system.model.ware.CellInfo;
import com.deer.wms.base.system.service.ware.ICellInfoService;
import com.deer.wms.base.system.util.ExcelReadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/excel")
public class HWDT_ExcelController {


    @Autowired
    private ICellInfoService cellInfoService;

    @GetMapping("/hwdtExcel")
    @ResponseBody
    public void hwdtExcel() throws IOException {
        int fristIndex = 0;//初始化sheet索引
        int lastIndex = 20;//设置最大的sheet索引
        String path ="C:\\Users\\L_dy\\Desktop\\1.xlsx";//解析的文件绝对路径


        CarCoord carCoord = new CarCoord();
        ExcelReadUtil excelReadUtil = new ExcelReadUtil();
        Map<String, List<String>> excelMap = excelReadUtil.read(fristIndex, lastIndex, path);

        List<String> cellList = excelMap.get("cellList");
        for (String cell :cellList){
            Integer pai= Integer.valueOf(cell.substring(0, 2));
            Integer lie= Integer.valueOf(cell.substring(2, 5));
            Integer floor= Integer.valueOf(cell.substring(5, 7));

            CellInfo cellInfo=new CellInfo();
            cellInfo.setShelfId(80);
            cellInfo.setCellCode(cell);
            cellInfo.setMemo("SRM"+pai+"巷道-"+pai+"排-"+lie+"列-"+floor+"层");

            //cellInfo.setsPai(pai);
            //cellInfo.setsLie(lie);

            //cellInfo.setsFloor(floor);
            cellInfo.setLength(0f);
            cellInfo.setWidth(0f);
            cellInfo.setHight(0f);

            if (lie==4){
                cellInfo.setState(8);
            }else {
                cellInfo.setState(0);
            }
            if (lie==3){
                cellInfo.setShelfId(90);
            }
            if(lie==1||lie==2){
                if(pai==5||pai==6||pai==10){
                    cellInfo.setState(0);
                    cellInfo.setShelfId(90);
                }
                else {
                    cellInfo.setState(8);
                }
            }
            cellInfo.setOrders(0);
            cellInfo.setItemId(0);
            int i = cellInfoService.insertCellInfo(cellInfo);
            System.out.println(i);
        }
    }
}
